#include "head.h"
int transFile(int sockfd, char *word){
    //v1.0 word : 文件名
    //v2.0 word : 文件的绝对
    train_t train;

    printf("test:%s\n",word);
    char *name = strtok(word, "/");
    char *p = name;
    while(p != NULL){
        name = p;
        p = strtok(NULL, "/");
    }

    char filename[128];
    strcpy(filename,p);
    int fd = open(word,O_RDWR);
    if(fd == -1){
        printf("%s is not existence!\n",filename);
    //    return 0;
        return -1;
    }
    strcpy(filename,word);
    train.length = strlen(filename);
    memcpy(train.data,filename,train.length);
    send(sockfd,&train.length,sizeof(train.length),0);
    send(sockfd,train.data,train.length,0);
    //
    //
    struct stat statbuf;
    fstat(fd,&statbuf);
    off_t filesize = statbuf.st_size;
    train.length = sizeof(filesize);
    memcpy(train.data,&filesize,train.length);
    send(sockfd,&train.length,sizeof(train.length),MSG_NOSIGNAL);
    send(sockfd,train.data,train.length,MSG_NOSIGNAL);

    //
    while(1){
        bzero(train.data,sizeof(train.data));
        ssize_t sret = read(fd,train.data,sizeof(train.data));
        train.length = sret;
        send(sockfd,&train.length,sizeof(train.length),0);
        send(sockfd,train.data,train.length,0);
        if(sret == 0)
            break;
    }

    close(fd);
    return 0;
}
